package com.york.tinyrpc.protoss.enums;

import lombok.Getter;

/**
 * 协议的消息状态枚举
 * 踩坑记录，根据字节数的限制修改常量值
 */
@Getter
public enum TinyRpcProtocolMessageStatusEnum {

    /**
     * 状态ok
     */
    OK("ok", 20),

    /**
     * 请求失败
     */
    BAD_REQUEST("badRequest", 40),

    /**
     * 响应失败
     */
    BAD_RESPONSE("badResponse", 50);

    /**
     * 状态说明
     */
    private final String text;

    /**
     * 状态值
     */
    private final int value;

    TinyRpcProtocolMessageStatusEnum(String text, int value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 根据状态值获取枚举
     *
     * @param value
     * @return
     */
    public static TinyRpcProtocolMessageStatusEnum getEnumByValue(int value) {
        for (TinyRpcProtocolMessageStatusEnum anEnum : TinyRpcProtocolMessageStatusEnum.values()) {
            if (anEnum.value == value) {
                return anEnum;
            }
        }
        return null;
    }

}
